package EJBTool.persistent.providers;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
import org.eclipse.gmf.runtime.common.core.service.IOperation;
import org.eclipse.gmf.runtime.common.ui.services.parser.GetParserOperation;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserProvider;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
import org.eclipse.gmf.runtime.notation.View;

/**
 * @generated
 */
public class EJBToolParserProvider extends AbstractProvider implements
		IParserProvider
{

	/**
	 * @generated
	 */
	private IParser entityBeanEJBName_4001Parser;

	/**
	 * @generated
	 */
	private IParser getEntityBeanEJBName_4001Parser()
	{
		if (entityBeanEJBName_4001Parser == null)
		{
			entityBeanEJBName_4001Parser = createEntityBeanEJBName_4001Parser();
		}
		return entityBeanEJBName_4001Parser;
	}

	/**
	 * @generated
	 */
	protected IParser createEntityBeanEJBName_4001Parser()
	{
		EAttribute[] features = new EAttribute[] { EJBTool.EJBToolPackage.eINSTANCE
				.getEntityBean_EJBName(), };
		EJBTool.persistent.parsers.MessageFormatParser parser = new EJBTool.persistent.parsers.MessageFormatParser(
				features);
		parser.setViewPattern("EJB = {0}");
		parser.setEditorPattern("EJB = {0}");
		parser.setEditPattern("EJB = {0}");
		return parser;
	}

	/**
	 * @generated
	 */
	private IParser entityBeanModuleName_4002Parser;

	/**
	 * @generated
	 */
	private IParser getEntityBeanModuleName_4002Parser()
	{
		if (entityBeanModuleName_4002Parser == null)
		{
			entityBeanModuleName_4002Parser = createEntityBeanModuleName_4002Parser();
		}
		return entityBeanModuleName_4002Parser;
	}

	/**
	 * @generated
	 */
	protected IParser createEntityBeanModuleName_4002Parser()
	{
		EAttribute[] features = new EAttribute[] { EJBTool.EJBToolPackage.eINSTANCE
				.getEntityBean_ModuleName(), };
		EJBTool.persistent.parsers.MessageFormatParser parser = new EJBTool.persistent.parsers.MessageFormatParser(
				features);
		parser.setViewPattern("Module = {0}");
		parser.setEditorPattern("Module = {0}");
		parser.setEditPattern("Module = {0}");
		return parser;
	}

	/**
	 * @generated
	 */
	private IParser entityBeanPrimaryKey_4003Parser;

	/**
	 * @generated
	 */
	private IParser getEntityBeanPrimaryKey_4003Parser()
	{
		if (entityBeanPrimaryKey_4003Parser == null)
		{
			entityBeanPrimaryKey_4003Parser = createEntityBeanPrimaryKey_4003Parser();
		}
		return entityBeanPrimaryKey_4003Parser;
	}

	/**
	 * @generated
	 */
	protected IParser createEntityBeanPrimaryKey_4003Parser()
	{
		EAttribute[] features = new EAttribute[] { EJBTool.EJBToolPackage.eINSTANCE
				.getEntityBean_PrimaryKey(), };
		EJBTool.persistent.parsers.MessageFormatParser parser = new EJBTool.persistent.parsers.MessageFormatParser(
				features);
		parser.setViewPattern("PrimaryKey = {0}");
		parser.setEditorPattern("PrimaryKey = {0}");
		parser.setEditPattern("PrimaryKey = {0}");
		return parser;
	}

	/**
	 * @generated
	 */
	protected IParser getParser(int visualID)
	{
		switch (visualID)
		{
			case EJBTool.persistent.edit.parts.EntityBeanEJBNameEditPart.VISUAL_ID:
				return getEntityBeanEJBName_4001Parser();
			case EJBTool.persistent.edit.parts.EntityBeanModuleNameEditPart.VISUAL_ID:
				return getEntityBeanModuleName_4002Parser();
			case EJBTool.persistent.edit.parts.EntityBeanPrimaryKeyEditPart.VISUAL_ID:
				return getEntityBeanPrimaryKey_4003Parser();
		}
		return null;
	}

	/**
	 * @generated
	 */
	public IParser getParser(IAdaptable hint)
	{
		String vid = (String) hint.getAdapter(String.class);
		if (vid != null)
		{
			return getParser(EJBTool.persistent.part.EJBToolVisualIDRegistry
					.getVisualID(vid));
		}
		View view = (View) hint.getAdapter(View.class);
		if (view != null)
		{
			return getParser(EJBTool.persistent.part.EJBToolVisualIDRegistry
					.getVisualID(view));
		}
		return null;
	}

	/**
	 * @generated
	 */
	public boolean provides(IOperation operation)
	{
		if (operation instanceof GetParserOperation)
		{
			IAdaptable hint = ((GetParserOperation) operation).getHint();
			if (EJBTool.persistent.providers.EJBToolElementTypes
					.getElement(hint) == null)
			{
				return false;
			}
			return getParser(hint) != null;
		}
		return false;
	}

	/**
	 * @generated
	 */
	public static class HintAdapter extends ParserHintAdapter
	{

		/**
		 * @generated
		 */
		private final IElementType elementType;

		/**
		 * @generated
		 */
		public HintAdapter(IElementType type, EObject object, String parserHint)
		{
			super(object, parserHint);
			assert type != null;
			elementType = type;
		}

		/**
		 * @generated
		 */
		public Object getAdapter(Class adapter)
		{
			if (IElementType.class.equals(adapter))
			{
				return elementType;
			}
			return super.getAdapter(adapter);
		}
	}

}
